package org.infodavid.common.notifier;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.infodavid.common.notifier.exceptions.NotifierException;
import org.infodavid.common.reflect.InstantiationHelper;

/**
 * The Class NotifierHelper.
 */
public abstract class NotifierHelper implements INotifier {

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 31974660168972479L;

	/** The Constant log. */
	private static final Log LOGGER = LogFactory.getLog(NotifierHelper.class);

	/** The singleton. */
	private static final NotifierHelper SINGLETON;

	static {
		try {
			SINGLETON = InstantiationHelper.getInstance().newInstance(NotifierHelper.class);
		}
		catch (final Throwable e) {
			LOGGER.error("An error occurs while instantiating singleton", e);

			throw new Error(e);
		}
	}

	/**
	 * returns the singleton.
	 * @return <code>NotifierHelper</code>
	 */
	public static NotifierHelper getInstance() {
		return SINGLETON;
	}

	/**
	 * Instantiates a new connection helper.
	 */
	protected NotifierHelper() {
		super();
	}

	/**
	 * Sets the notifier application address.
	 * @param value the new notifier address
	 */
	public abstract void setNotifierAddress(final String value);

	/**
	 * Gets the notifier application address.
	 * @return the notifier address
	 */
	public abstract String getNotifierAddress();

	/**
	 * Throw an exception if an error is described in given acknowledgments.
	 * @param acknowledgments the acknowledgments
	 * @throws NotifierException the notifier exception
	 */
	public abstract void throwExceptionIfError(IAcknowledgment... acknowledgments)
	    throws NotifierException;

	/**
	 * Logs a warning if an error is described in given acknowledgments.
	 * @param acknowledgments the acknowledgments
	 * @throws NotifierException the notifier exception
	 */
	public abstract void warnIfError(IAcknowledgment... acknowledgments) throws NotifierException;
}
